home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2001 / MacHack 2001.toast / pc / The Hacks / SpellCompositor / SpellViewFrame.java < prev   
Encoding:
Java Source  |  2001-06-23  |  13.4 KB  |  448 lines

  1. /*
  2.     ArcanaApp.SpellViewFrame
  3.         - a means by which to view spell records
  4.     
  5.     Written by Scott C. Ziegler for use with Simulcra™.
  6.     
  7.     Usage:
  8.         
  9.         void clearFields() - clears the fields of data.
  10.         void displaySpell(Arcana.SpellRecord rec) - displays the param spell in Frame.
  11.         void setNavigationListener(ActionListener nl) - removes default ActionListener
  12.             and replaces it with param ActionListener.  This listener watches the navigation
  13.             buttons (Back, Next, PrevLvl, FwdLevel)
  14.         void setManipulationListener(ActionListener ml) - removes default ActionListener
  15.             and replaces it with param ActionListener.  This listener watches the manipulation
  16.             buttons (Edit, Delete, Find, New)
  17.         void setAboutListener(ActionListener al) - removes default ActionListener
  18.             and replaces it with param ActionListener. Controls about menuItem.
  19.         void setQuitListener(ActionListener ql)removes default ActionListener
  20.             and replaces it with param ActionListener. Controls quit behavior.
  21.     
  22.     vers. history:
  23.         06.22.00 - reached first syntactically stable point.
  24.         09.19.00 - decided to overhaul the project using layout managers
  25.         10.25.00 - began project to make a functional spell book app
  26.     
  27.     Work Needed:
  28.         - ****** NEED NEED to make AreaOfEffect field presence
  29.         - *** NEED to make a scroll bar for the description TextArea
  30.         - finish initMenus()
  31.         - add JDialog warnings to Delete button and other destructive updates.
  32.     
  33.     Work Completed:
  34.         - made event structure for buttons;
  35.         - populated the menubar with some menuitems linked to events.
  36.         - finished debugging errors in display functions.
  37.         - implemented clearFields and displaySpell
  38.  
  39. */
  40.  
  41. /*
  42. This file and its intellectual contents are considered property of the creator and are to be treated as such with respect to use in other applications.  Any use of this software for any purpose whatsoever must have explicit permission from the author of the file.  This code is part of an ongoing development process for future possible products, and so is considered private property.
  43. Do not use without permission.  Author: Scott C. Ziegler <Aslan@Narnia.net>
  44. */
  45.  
  46. package Thoth;
  47.  
  48. import java.awt.*;
  49. import java.awt.event.*;
  50. import java.util.*;
  51.  
  52. import javax.swing.*;
  53. import javax.swing.border.*;
  54. import javax.swing.event.*;
  55.  
  56. public class SpellViewFrame extends JFrame {
  57.     
  58.     Insets objectInsets = new Insets(2,2,2,2);
  59.     
  60.     // Panels
  61.     
  62.     JPanel         buttonPanel;
  63.     JPanel        recordPanel;
  64.     
  65.     // Menus
  66.     
  67.     JMenuBar            menuBar;
  68.     JMenu                fileMenu;
  69.         JMenuItem            aboutBoxMenuItem;
  70.         JMenuItem            quitMenuItem;
  71.     JMenu                editMenu;
  72.         JMenuItem            undoMenuItem;
  73.         JMenuItem            cutMenuItem;
  74.         JMenuItem            copyMenuItem;
  75.         JMenuItem            pasteMenuItem;
  76.     JMenu                optionsMenu;
  77.         JMenuItem             optionsMenuItem;
  78.     JMenu                someMenu;
  79.         JMenuItem            someMenuItem;
  80.     
  81.     // Buttons
  82.     
  83.     JButton        backButton;
  84.     JButton        nextButton;
  85.     JButton        prevLvlButton;
  86.     JButton        fwdLvlButton;
  87.     JButton        editButton;
  88.     JButton        deleteButton;
  89.     JButton        findButton;
  90.     JButton        newButton;
  91.     
  92.     // Labels
  93.     
  94.     JLabel        nameLabel;
  95.     JLabel        levelLabel;
  96.     JLabel        schoolLabel;
  97.     JLabel        componentsLabel;
  98.     JLabel        rangeLabel;
  99.     JLabel        durationLabel;
  100.     JLabel        castingTimeLabel;
  101.     JLabel        areaOfEffectLabel;
  102.     JLabel        savingThrowLabel;
  103.     JLabel        descriptionLabel;
  104.     
  105.     // Text Fields
  106.     
  107.     JTextField        nameTextField;
  108.     JTextField        levelTextField;
  109.     JTextField        schoolTextField;
  110.     JTextField        componentsTextField;
  111.     JTextField        rangeTextField;
  112.     JTextField        durationTextField;
  113.     JTextField        castingTimeTextField;
  114.     JTextField        areaOfEffectTextField;
  115.     JTextField        savingThrowTextField;
  116.     
  117.     JScrollPane        descriptionScrollPane;
  118.     JTextArea        descriptionTextArea;
  119.     
  120.     ActionListener    navigationActionListener;
  121.     ActionListener    manipulationActionListener;
  122.     ActionListener    aboutListener;
  123.     ActionListener    quitListener;
  124.     
  125.     // Constructors
  126.     
  127.     public SpellViewFrame() {
  128.         super("Arcana Spell View");
  129.         
  130.         initMenus();
  131.         initButtons();
  132.         initRecordPanel();
  133.         initDescriptionArea();
  134.         
  135.         setJMenuBar(menuBar);
  136.         Container progFrameContentPane = getContentPane();
  137.         progFrameContentPane.add(buttonPanel, BorderLayout.NORTH);
  138.         progFrameContentPane.add(recordPanel, BorderLayout.CENTER);
  139.         progFrameContentPane.add(descriptionScrollPane, BorderLayout.SOUTH);
  140.         
  141.         setSize(new Dimension(500,600));
  142.         //setVisible(true);
  143.         
  144.         addWindowListener(new java.awt.event.WindowAdapter() {
  145.             public void windowClosing(java.awt.event.WindowEvent e) {
  146.                 thisWindowClosing(e);
  147.                 }
  148.             });
  149.         }
  150.         
  151.     // Selectors
  152.     
  153.     
  154.     // Mutators
  155.     
  156.     public void setNavigationListener(ActionListener nl) {
  157.         backButton.removeActionListener(navigationActionListener);
  158.         backButton.addActionListener(nl);
  159.         nextButton.removeActionListener(navigationActionListener);
  160.         nextButton.addActionListener(nl);
  161.         fwdLvlButton.removeActionListener(navigationActionListener);
  162.         fwdLvlButton.addActionListener(nl);
  163.         prevLvlButton.removeActionListener(navigationActionListener);
  164.         prevLvlButton.addActionListener(nl);
  165.         }
  166.         
  167.     public void setManipulationListener(ActionListener ml) {
  168.         editButton.removeActionListener(manipulationActionListener);
  169.         editButton.addActionListener(ml);
  170.         deleteButton.removeActionListener(manipulationActionListener);
  171.         deleteButton.addActionListener(ml);
  172.         findButton.removeActionListener(manipulationActionListener);
  173.         findButton.addActionListener(ml);
  174.         newButton.removeActionListener(manipulationActionListener);
  175.         newButton.addActionListener(ml);
  176.         }
  177.         
  178.     public void setAboutListener(ActionListener al) {
  179.         aboutBoxMenuItem.removeActionListener(aboutListener);
  180.         aboutBoxMenuItem.addActionListener(al);
  181.         }
  182.         
  183.     public void setQuitListener(ActionListener ql) {
  184.         quitMenuItem.removeActionListener(quitListener);
  185.         quitMenuItem.addActionListener(ql);
  186.         }
  187.         
  188.     // Methods
  189.     
  190.     public void clearFields() {
  191.         nameTextField.setText("");
  192.         levelTextField.setText("");
  193.         schoolTextField.setText("");
  194.         componentsTextField.setText("");
  195.         rangeTextField.setText("");
  196.         durationTextField.setText("");
  197.         castingTimeTextField.setText("");
  198.         areaOfEffectTextField.setText("");
  199.         savingThrowTextField.setText("");
  200.         descriptionTextArea.setText("");
  201.         }
  202.         
  203.     public void displaySpell(Arcana.SpellRecord spell) {
  204.         nameTextField.setText(spell.getName());
  205.         levelTextField.setText("" + spell.getLevel());
  206.         schoolTextField.setText(spell.getSchool());
  207.         switch (spell.getComponents()) {
  208.             case 0 :
  209.                 componentsTextField.setText("Verbal");
  210.                 break;
  211.             case 1 :
  212.                 componentsTextField.setText("Somantic");
  213.                 break;
  214.             case 2 :
  215.                 componentsTextField.setText("Material");
  216.                 break;
  217.             case 3 :
  218.                 componentsTextField.setText("Verbal, Somantic");
  219.                 break;
  220.             case 4 :
  221.                 componentsTextField.setText("Somantic, Material");
  222.                 break;
  223.             case 5 :
  224.                 componentsTextField.setText("Verbal, Material");
  225.                 break;
  226.             case 6 :
  227.                 componentsTextField.setText("Verbal, Somantic, Material");
  228.                 break;
  229.             }
  230.         rangeTextField.setText(spell.getRange());
  231.         durationTextField.setText(spell.getDuration());
  232.         castingTimeTextField.setText(spell.getCastingTime());
  233.         areaOfEffectTextField.setText(spell.getAreaOfEffect());
  234.         savingThrowTextField.setText(spell.getSavingThrow());
  235.         descriptionTextArea.setText(spell.getEffect().getDescription());
  236.         }
  237.     
  238.     private void initMenus() {
  239.         menuBar = new JMenuBar();
  240.         menuBar.setBorder(new BevelBorder(BevelBorder.RAISED));
  241.  
  242.         fileMenu = new JMenu("File");
  243.         fileMenu.setMnemonic('F');
  244.         aboutBoxMenuItem = new JMenuItem("About…");
  245.         fileMenu.add(aboutBoxMenuItem);
  246.         aboutListener = new ActionListener() {
  247.             public void actionPerformed(ActionEvent ae) {
  248.                 System.out.println("About!");
  249.                 }
  250.             };
  251.         aboutBoxMenuItem.addActionListener(aboutListener);
  252.         quitMenuItem = new JMenuItem("Quit");
  253.         fileMenu.add(quitMenuItem);
  254.         quitListener = new ActionListener() {
  255.             public void actionPerformed(ActionEvent ae) {
  256.                 //System.exit(0);
  257.                 System.out.println("Quit!");
  258.                 }
  259.             };
  260.         quitMenuItem.addActionListener(quitListener);
  261.         editMenu = new JMenu("Edit");
  262.         undoMenuItem = new JMenuItem("Undo");
  263.         editMenu.add(undoMenuItem);
  264.         cutMenuItem = new JMenuItem("Cut");
  265.         editMenu.add(cutMenuItem);
  266.         copyMenuItem = new JMenuItem("Copy");
  267.         editMenu.add(copyMenuItem);
  268.         pasteMenuItem = new JMenuItem("Paste");
  269.         editMenu.add(pasteMenuItem);
  270.         optionsMenu = new JMenu("Options");
  271.         optionsMenuItem = new JMenuItem("Options…");
  272.         optionsMenu.add(optionsMenuItem);
  273.         someMenu = new JMenu("Something");
  274.         someMenuItem = new JMenuItem("Something…");
  275.         menuBar.add(fileMenu);
  276.         menuBar.add(editMenu);
  277.         menuBar.add(optionsMenu);
  278.         menuBar.add(someMenu);
  279.         }
  280.         
  281.     private void initButtons() {
  282.         // this needs to be moved to the app side
  283.         navigationActionListener = new ActionListener() {
  284.             public void actionPerformed(ActionEvent ae) {
  285.                 String com = ae.getActionCommand();
  286.                      if (com.compareTo("Back") == 0) {
  287.                          
  288.                         }
  289.                 else if (com.compareTo("Next") == 0) {
  290.                     
  291.                     }
  292.                 else if (com.compareTo("PrevLvl") == 0) {
  293.                     
  294.                     }
  295.                 else if (com.compareTo("FwdLvl") == 0) {
  296.                 
  297.                     }
  298.                 }
  299.             };
  300.             
  301.         // this needs to be moved to the app side
  302.         manipulationActionListener = new ActionListener() {
  303.             public void actionPerformed(ActionEvent ae) {
  304.                 String com = ae.getActionCommand();
  305.                      if (com.compareTo("Edit") == 0) {
  306.                          
  307.                         }
  308.                 else if (com.compareTo("Delete") == 0) {
  309.                     
  310.                     }
  311.                 else if (com.compareTo("Find") == 0) {
  312.                     
  313.                     }
  314.                 else if (com.compareTo("New") == 0) {
  315.                 
  316.                     }
  317.                 }
  318.             };
  319.         backButton = new JButton("Back");
  320.         backButton.addActionListener(navigationActionListener);
  321.         nextButton = new JButton("Next");
  322.         nextButton.addActionListener(navigationActionListener);
  323.         prevLvlButton = new JButton("PrevLvl");
  324.         prevLvlButton.addActionListener(navigationActionListener);
  325.         fwdLvlButton = new JButton("FwdLvl");
  326.         fwdLvlButton.addActionListener(navigationActionListener);
  327.         editButton = new JButton("Edit");
  328.         editButton.addActionListener(manipulationActionListener);
  329.         deleteButton = new JButton("Delete");
  330.         deleteButton.addActionListener(manipulationActionListener);
  331.         findButton = new JButton("Find");
  332.         findButton.addActionListener(manipulationActionListener);
  333.         newButton = new JButton("New");
  334.         newButton.addActionListener(manipulationActionListener);
  335.         
  336.         buttonPanel = new JPanel();
  337.         buttonPanel.setLayout(new GridLayout(2,4,5,5));
  338.         buttonPanel.add(backButton);
  339.         buttonPanel.add(nextButton);
  340.         buttonPanel.add(editButton);
  341.         buttonPanel.add(deleteButton);
  342.         buttonPanel.add(prevLvlButton);
  343.         buttonPanel.add(fwdLvlButton);
  344.         buttonPanel.add(findButton);
  345.         buttonPanel.add(newButton);
  346.         }
  347.     
  348.     private void initRecordPanel() {
  349.         recordPanel = new JPanel();
  350.         recordPanel.setLayout(new GridBagLayout());
  351.         GridBagConstraints c = new GridBagConstraints();
  352.         
  353.         nameLabel = new JLabel("Name:");
  354.         nameTextField = new JTextField();
  355.         levelLabel = new JLabel("Level:");
  356.         levelTextField = new JTextField();
  357.         schoolLabel = new JLabel("School:");
  358.         schoolTextField = new JTextField();
  359.         componentsLabel = new JLabel("Components:");
  360.         componentsTextField = new JTextField();
  361.         rangeLabel = new JLabel("Range:");
  362.         rangeTextField = new JTextField();
  363.         durationLabel = new JLabel("Duration:");
  364.         durationTextField = new JTextField();
  365.         castingTimeLabel = new JLabel("Casting Time:");
  366.         castingTimeTextField = new JTextField();
  367.         areaOfEffectLabel = new JLabel("Area Of Effect:");
  368.         areaOfEffectTextField = new JTextField();
  369.         savingThrowLabel = new JLabel("Saving Throw:");
  370.         savingThrowTextField = new JTextField();
  371.         descriptionLabel = new JLabel("Description:");
  372.         
  373.         setGBConstraints(c,0,0,true);
  374.         recordPanel.add(nameLabel, c);
  375.         setGBConstraints(c,1,0,false);
  376.         recordPanel.add(nameTextField, c);
  377.         
  378.         setGBConstraints(c,0,1,true);
  379.         recordPanel.add(levelLabel, c);
  380.         setGBConstraints(c,1,1,false);
  381.         recordPanel.add(levelTextField, c);
  382.         
  383.         setGBConstraints(c,0,2,true);
  384.         recordPanel.add(schoolLabel, c);
  385.         setGBConstraints(c,1,2,false);
  386.         recordPanel.add(schoolTextField, c);
  387.         
  388.         setGBConstraints(c,0,3,true);
  389.         recordPanel.add(componentsLabel, c);
  390.         setGBConstraints(c,1,3,false);
  391.         recordPanel.add(componentsTextField, c);
  392.         
  393.         setGBConstraints(c,0,4,true);
  394.         recordPanel.add(rangeLabel, c);
  395.         setGBConstraints(c,1,4,false);
  396.         recordPanel.add(rangeTextField, c);
  397.         
  398.         setGBConstraints(c,0,5,true);
  399.         recordPanel.add(durationLabel, c);
  400.         setGBConstraints(c,1,5,false);
  401.         recordPanel.add(durationTextField, c);
  402.         
  403.         setGBConstraints(c,0,6,true);
  404.         recordPanel.add(castingTimeLabel, c);
  405.         setGBConstraints(c,1,6,false);
  406.         recordPanel.add(castingTimeTextField, c);
  407.         
  408.         setGBConstraints(c,0,7,true);
  409.         recordPanel.add(savingThrowLabel, c);
  410.         setGBConstraints(c,1,7,false);
  411.         recordPanel.add(savingThrowTextField, c);
  412.         
  413.         setGBConstraints(c,0,8,true);
  414.         recordPanel.add(areaOfEffectLabel, c);
  415.         setGBConstraints(c,1,8,false);
  416.         recordPanel.add(areaOfEffectTextField, c);
  417.         
  418.         setGBConstraints(c,0,9,true);
  419.         recordPanel.add(descriptionLabel, c);
  420.         }
  421.         
  422.     private void setGBConstraints(GridBagConstraints gbc, int x, int y, boolean lbl_field) {
  423.         gbc.gridx = x; gbc.gridy = y; gbc.gridheight = 1; gbc.gridwidth = 1;
  424.         gbc.weightx = (lbl_field?20:80); gbc.weighty = 11;
  425.         gbc.fill = (lbl_field?GridBagConstraints.NONE:GridBagConstraints.BOTH);
  426.         gbc.anchor = (lbl_field?GridBagConstraints.WEST:GridBagConstraints.CENTER);
  427.         gbc.insets = objectInsets;
  428.         }
  429.         
  430.     private void initDescriptionArea() {
  431.         descriptionScrollPane = new JScrollPane();
  432.         descriptionTextArea = new JTextArea();
  433.         descriptionTextArea.setRows(15);
  434.         descriptionTextArea.setLineWrap(true);
  435.         descriptionTextArea.setWrapStyleWord(true);
  436.         descriptionScrollPane.getViewport().add(descriptionTextArea);
  437.         // sizing?
  438.         }
  439.     
  440.     void thisWindowClosing(java.awt.event.WindowEvent e) {
  441.         setVisible(false);
  442.         // dispose();
  443.         // System.exit(0);
  444.         }
  445.     // Selectors
  446.     
  447.     }
  448.